<template>
  <div class="hello">
    <div class="btn"
      @click="sendevent">发送事件(控制台看效果)</div>
      <div class="btn cancel"
      @click="cancel">取消监听eventkey1,eventkey2</div>
       <div class="btn cancel"
      @click="onceevent">只监听一次eventkey1</div>
  </div>
</template>

<script>
import eventbus from "./utils/emitter";
export default {
  name: "HelloWorld",
  props: {
    msg: String,
  },
  methods: {
    sendevent() {
      eventbus.emit("eventkey", "a");
      eventbus.emit("eventkey1", "a", "b");
      eventbus.emit("eventkey2", "a", "b", "c");
    },
    cancel(){
      eventbus.off("eventkey1");
      eventbus.off("eventkey2");
    },
    onceevent(){
     eventbus.once("eventkey1", (res, res1) => {
      console.log("一次eventkey1", res, res1);
    });
    }
  },
  mounted() {
    eventbus.on("eventkey", (res) => {
      console.log("eventkey", res);
    });
    eventbus.on("eventkey1", (res, res1) => {
      console.log("eventkey1", res, res1);
    });
    eventbus.on("eventkey2", (res, res1, res2) => {
      console.log("eventkey2", res, res1, res2);
    });
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped >
.hello{
  display: flex;
  flex-direction: column;
}
.btn {
  margin: 0 auto;
  height: 50px;
  background-color: antiquewhite;
  line-height: 50px;
  border-radius: 50px;
  margin-bottom: 20px;
  display: inline-block;
  padding: 0 20px;
}
.cancel{
}
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
